$(function () {
    let siteInfo = getStorage("siteInfo");
    let id = siteInfo.id;
    let name = siteInfo.name;
    let cid = siteInfo.cid;
    let userId = getStorage("loginUserId");
    if (window.history.length>1){
        $('#btn').show()
    }else{
        $('#btn').hide()
    }
    
    $("#mytables").niceScroll()
    site.updatePoint(id);
    updateAqifor24(id, "chartAqi24");
    //联网率
    updateDeviceStatus(id, "chartDevice");
});
function getAqiIndex(aqi) {
    var index = 0;
    if (aqi <= 1) {
        index = 0;
    } else if (aqi <= 2) {
        index = 1;
    } else if (aqi <= 3) {
        index = 2;
    } else if (aqi <= 4) {
        index = 3;
    } else if (aqi <= 5) {
        index = 4;
    } else {
        index = 5;
    }
    return index;
};
// 基类
var site = { 
    /**
     * 更新指数
     * @id 站点编号
     */
   updatePoint: function (id) {
  //获取站点数据
  api.getSite2(id, function (d) {
    console.log("站点数据",d)
    $("#update").text(dateFormat(d.fupddate));
      var wd = d.fwd;
      var sd = d.fsd;
      if(d.faqi>300)
      {
        $("#zhizhenbox").css({'left':'300px'})
      }
      else
      {
        $("#zhizhenbox").css({'left':d.faqi+'px'})
      }
      
    //   $("#exponent").html(d.faqi);
      var index = getAqiIndex(d.faqi);
      $("#exponent").html(getAqiDes(index));
      reloadExponen(d.faqi);
      if(d.fcontaminants != null)
      {
        $("#fcontaminants").text(d.fcontaminants);
      }
      else
      {
      $("#fcontaminants").text('暂无数据');

      }
      if(d.fyx!=null)
      {
        $("#fyx").text(d.fyx);
      }
      else
      {
      $("#fyx").text('暂无数据')
      }
      if(d.fcs!=null)
      {
        $("#fcs").text(d.fcs);
      }
      else
      {
      $("#fcs").text('暂无数据')
      }
    //   $("#fyx").text(d.fyx);
    //   $("#fcs").text(d.fcs);
      //获取天气数据
      api.getWeather(name, function (weat) {
        if(wd == null && sd == null){
            $("#weather").html('天气:' + weat.wea + '  ' + weat.win + ' ' + weat.win_speed);
        }else if(wd == null){
            $("#weather").html('天气:' + weat.wea + '  ' + weat.win + ' ' + weat.win_speed + ' 湿度:' + sd + '%');
        }else if(sd == null){
            $("#weather").html('天气:' + weat.wea + '  ' + weat.win + ' ' + weat.win_speed + ' 温度:' + wd + '℃');
        }else{
            $("#weather").html('天气:' + weat.wea + '  ' + weat.win + ' ' + weat.win_speed + ' 温度:' + wd + '℃' + ' 湿度:' + sd + '%');
        }
      });
  });
}
}
/**
 * 更新24小时AQI
 * @id 站点编号
 * @charId 图表编号
 */
 function updateAqifor24(id, chartId) {
    api.getsiteAqi2(id, function (d) {
        reloadchartAqi24(chartId, d);
    });
};


function getUrl(id, name) {
    let siteInfo = getStorage("siteInfo");
    let cid = siteInfo.cid;
    return `indoor.html?id=${id}&name=${name}&tenantNo=${cid}`;
}
